<?php
namespace Goyello\MVC\Model;

abstract class Model
{
    protected $db;

    public function __construct()
    {
        $this->db = new \PDO('mysql:host=' . Config::DB_HOST. ';dbname='.Config::DB_NAME, Config::DB_USER, Config::DB_PASS);
    }

    protected function escape($sql)
    {
        return addslashes($sql);
    }

    protected function entity($sql)
    {
        return htmlspecialchars($sql);
    }

    protected function fetchAllAssoc($sql)
    {
        $sth = $this->db->prepare($sql);
        $sth->execute();
        return $sth->fetchAll(\PDO::FETCH_ASSOC);
    }

    protected function exec($sql)
    {
        $sql = $this->entity($sql);
        return $this->db->exec($sql);
    }
}
